package edu.uwm.cs552;

import java.awt.Point;

public enum PlayerEditAction {
	PLAN_MOVEMENT("Move Train") {
		public void apply(Player player, Point p, double scale) {
			HexCoordinate h = HexCoordinate.fromPoint(p, scale);
			player.planMovement(h, false);
		}		
	},
	PROPOSE_TRACK("Build Track") {
		public void apply(Player player, Point p, double scale) {
			HexEdge e = HexEdge.fromPoint(p, scale, BOUND);
			if (e != null) {
				player.proposeConstruction(e, false);
			}
		}
	},
	CLEAR_PLAN("Clear Move") {
		public void apply(Player player, Point p, double scale) {
			HexCoordinate h = HexCoordinate.fromPoint(p, scale);
			player.planMovement(h, true);
		}
	},
	CLEAR_PROPOSAL("Clear Build") {
		public void apply(Player player, Point p, double scale) {
			HexEdge e = HexEdge.fromPoint(p, scale, BOUND);
			if (e != null) {
				player.proposeConstruction(e, true);
			}
		}
	};

	public static final double BOUND = 0.50;
	
	private final String name;
	
	private PlayerEditAction(String s) {
		name = s;
	}

	/**
	 * Perform the action at the given point on a hex board.
	 * @param player player performing the action, must not be null
	 * @param p point on screen, must not be null
	 * @param scale scale of hexagons (pixels per hexagon width)
	 */
	public abstract void apply(Player player, Point p, double scale);

	@Override
	public String toString() {
		return name;
	}
}
